<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const user = {
        gender: 2,
        get cnGender() {
          const obj = { 1: "男", 2: "女" };
          return obj[this.gender];
        },
        set cnGender(value) {
          const obj = { 男: 1, 女: 2 };
          this.gender = obj[value];
        },

        get enGender() {
          const obj = { 1: "boy", 2: "girl" };
          return obj[this.gender];
        },
        set enGender(value) {
          const obj = { boy: 1, girl: 2 };
          this.gender = obj[value];
        },
      };

      // user.cnGender = "男";
      // console.log(user.cnGender); // 男

      user.enGender = "boy";
      console.log(user.enGender); // boy
    </script>
  </body>
</html>
